<template>
	<view class="body">
		<uni-section title="会议信息" padding="20rpx 40rpx;">
			<view class="row-input">
				<text class="star">*</text>
				<text class="label">会议室:</text>
				<input type="text" class="editor" :value="roomName" disabled maxlength="20" />
			</view>

			<view class="row-input mt-10">
				<text class="star">*</text>
				<text class="label">会议标题:</text>
				<input type="text" class="editor" placeholder="请输入会议标题" v-model="title" maxlength="30" />
			</view>

			<view class="row-input mt-10">
				<text class="star">*</text>
				<text class="label">会议日期:</text>
				<picker class="date-wrap" mode="date" :value="date" :start="startDate" :end="endDate"
					@change="bindDateChange">
					<view class="editor">{{date}}</view>
				</picker>
			</view>

			<view class="row-input mt-10">
				<text class="star">*</text>
				<text class="label">会议时间:</text>
				<view class="date-wrap">
					<picker class="date-item" mode="time" :value="begin_time" @change="bindTimeChangeStart"
						style="flex: 1;">
						<view class="editor">{{begin_time}}</view>
					</picker>
					<view class="time-spe">➖</view>
					<picker class="date-item" mode="time" :value="end_time" @change="bindTimeChangeEnd" style="flex: 1;">
						<view class="editor">{{end_time}}</view>
					</picker>
				</view>
			</view>

			<view class="row-input mt-10">
				<text class="star hide">*</text>
				<text class="label">概要:</text>
				<textarea class="editor remark" v-model="metting_remark" placeholder="会议概要(选填)" maxlength="100"
					style="padding: 20rpx 20rpx;"></textarea>
			</view>
		</uni-section>

		<!-- <uni-section title="参会成员" padding="20rpx 40rpx;" class="mt-10" @click="chooseMem">
			<template v-slot:right>
				<image src="@/static/ic_arrow_r.png" class="arrow-r"></image>
			</template>
			<view class="member-wrap">
				张三、李四、王五
			</view>
		</uni-section> -->
		<view class="btn-wrap">
			<button type="default" class="btn" @click="save">保存修改</button>
		</view>
	</view>
</template>

<script>
	import cfg from '@/utils/config.js'
	import time_util from '@/utils/time_util.js'
	export default {
		data() {
			return {
				id: null,

				roomName: '',
				title: '',
				date: '',
				begin_time: '',
				end_time: '',
				metting_remark: '',
				isMine: null
			}
		},
		onLoad(param) {
			this.id = param.id
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			bindDateChange(e) {
				this.date = e.detail.value
			},
			bindTimeChangeStart(e) {
				this.begin_time = e.detail.value
			},
			bindTimeChangeEnd(e) {
				this.end_time = e.detail.value
			},
			getDetail() {
				if (!this.id) {
					return
				}
				uni.request({
					url: cfg.host + 'meeting/get/' + this.id,
					method: 'GET',
					success: (res) => {
						if (res.data.code == 0) {
							let data = res.data.data
							this.roomName = data.roomName
							this.title = data.title
							this.metting_remark = data.desc

							this.date = time_util.getYMD(data.beginTime)
							this.begin_time = time_util.getHM(data.beginTime)
							this.end_time = time_util.getHM(data.endTime)
							this.isMine = data.isMine
						}
					}
				})
			},
			save() {
				if (this.id == null) {
					uni.showToast({
						title: 'ID不能为空',
						icon: 'none'
					})
					return
				}
				if (!this.title.trim()) {
					uni.showToast({
						title: '请填写会议标题',
						icon: 'none'
					})
					return
				}
				if (!this.date.trim()) {
					uni.showToast({
						title: '请选择会议日期',
						icon: 'none'
					})
					return
				}
				if (!this.begin_time.trim() || !this.end_time.trim()) {
					uni.showToast({
						title: '请选择会议起始时间',
						icon: 'none'
					})
					return
				}

				uni.request({
					url: cfg.host + 'meeting/update',
					method: 'POST',
					data: {
						id: this.id,
						title: this.title,
						desc: this.metting_remark,
						beginTime: this.date + " " + this.begin_time + ":00",
						endTime: this.date + " " + this.end_time + ":00"
					},
					success: (res) => {
						if (res.data.code == 0) {
							uni.showToast({
								title: '修改成功',
								icon: 'success'
							})
							setTimeout(() => {
								uni.navigateBack()
							}, 1000)
						} else {
							let msg = res.data.msg || '修改失败'
							uni.showToast({
								title: msg,
								icon: 'error'
							})
						}
					},
					fail: () => {
						uni.showToast({
							title: '修改失败',
							icon: 'error'
						})
					}
				})
			}

		}
	}
</script>

<style lang="scss">
	.date-wrap {
		display: flex;
		flex-direction: row;
		flex: 1;

		.date-item {
			flex: 1;
		}
	}

	.time-spe {
		margin-left: 20rpx;
		margin-right: 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}

	.remark {
		height: 150rpx;
		border: 1rpx solid #f4f4f4;
		box-sizing: border-box;
	}

	.member-wrap {
		font-size: 28rpx;
	}

	.btn-wrap {
		display: flex;
		flex-direction: row;
		margin-top: 30rpx;
	}
</style>